package cn.cupk.logsystem.log.singletonpattern;

import cn.cupk.logsystem.log.observerPattern.Logger;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

public class LogManager {
    @Getter
    private static final LogManager instance = new LogManager();
    private final List<Logger> loggers = new ArrayList<>();

    private LogManager() {}

    public Logger getLogger(String name) {
        for (Logger logger : loggers) {
            if (logger.getName().equals(name)) {
                return logger;
            }
        }
        Logger newLogger = new Logger(name);
        loggers.add(newLogger);
        return newLogger;
    }
}